package model;
import java.io.*;
import java.util.*;

/**
 * Used to read data from a text file.
 * 
 * @author Kenny Chong, Dan End, James Ju
 * CSE 333 : User Interface
 * Project HMSystem */

public class FileRead 
{
	
	private File fileToRead;
	private FileReader fileReader;
	
	private BufferedReader bufferedReader;

	/**
	 * Construct the fileReader.
	 */
	public FileRead(String directory)
	{
		// Attempt to read the file from directory.
		try 
		{
			fileToRead = new File(directory);
			fileReader = new FileReader(fileToRead);
			bufferedReader = new BufferedReader(fileReader);
		} catch (IOException ex) {
			ex.printStackTrace();
		}
	}
	
	/**
	 * Parse the file and store it in a list.
	 * @return
	 */
	public ArrayList<String> parse()
	{	
		String line = null;
		
		ArrayList<String> list = new ArrayList<String>();
		
		try 
		{
			while((line = bufferedReader.readLine()) != null)
			{
				list.add(line);
			}
			
		bufferedReader.close();
		
		} catch (IOException ex) {
			System.out.println(ex);
		}
		
		return list;
	}
}
